package com.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.bean.SupplierBean;
import com.project.mapper.ISupplierMapper;
import com.project.service.ISupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
@Transactional
public class SupplierServiceImpl implements ISupplierService {
    @Autowired
    private ISupplierMapper mapper;
    @Override
    public Page<SupplierBean> findByItem(Integer pageNo, String name, String ranges) {
        QueryWrapper<SupplierBean> qw = new QueryWrapper<>();
        if (name!=null&&name.length()!=0){
            qw.like("s_name",name);
        }
        if (ranges!=null&& ranges.length()!=0){
            qw.like("s_range",ranges);
        }

        return mapper.selectPage(new Page(pageNo,5),qw) ;
    }

    @Override
    public SupplierBean findById(Integer id) {

        return mapper.selectById(id);
    }

    @Override
    public void update(Integer id, String cadre, String phone) {
         SupplierBean supplierBean = new SupplierBean();
         supplierBean.setId(id);
         supplierBean.setCadre(cadre);
         supplierBean.setPhone(phone);
         mapper.updateById(supplierBean);
    }

    @Override
    public void add(SupplierBean supplier) {
         mapper.insert(supplier);
    }

    @Override
    public List<SupplierBean> findAll() {
        return mapper.selectList(null);
    }

    @Override
    public void addList(List<SupplierBean> supplierList) {
           mapper.addList(supplierList);
    }
}
